package logic

import (
	"context"
	"tiktok/model/mysql"
	"tiktok/tiktokrpc/internal/svc"
	"tiktok/tiktokrpc/tiktokrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentLogic {
	return &AddCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddCommentLogic) AddComment(in *tiktokrpc.AddCommentRequest) (*tiktokrpc.AddCommentResponse, error) {
	// todo: add your logic here and delete this line

	comment := mysql.TikTokComment{
		TikTokContentId: in.ContentId,
		TikTokUserId:    in.UserId,
		Content:         in.Content,
	}

	mysql.DB.Debug().Create(&comment)

	return &tiktokrpc.AddCommentResponse{
		Id: int64(comment.ID),
	}, nil
}
